import 'http_exception.dart';

class HttpResponseData {
  late bool isSuccess;
  dynamic data;
  CustomHttpException? error;

  HttpResponseData._internal({this.isSuccess = false});

  HttpResponseData.success(this.data) {
    isSuccess = true;
  }

  HttpResponseData.failure({String? msg, String? code, this.data}) {
    error = BadRequestException(msg: msg, code: code);
    isSuccess = false;
  }

  HttpResponseData.failureFormResponse(responseMsg, responseCode, data) {
    error = BadResponseException(responseMsg, responseCode, data: data);
    isSuccess = false;
  }

  HttpResponseData.failureFromError([CustomHttpException? e]) {
    error = e ?? UnknownException();
    isSuccess = false;
  }
  HttpResponseData.failurCustom({String? msg, String? code, this.data}) {
    error = BadRequestException(msg: msg, code: code);
    isSuccess = false;
  }

  @override
  String toString() {
    StringBuffer sb = StringBuffer('{');
    sb.write("\"isSuccess\":\"$isSuccess\"");
    sb.write(",\"data\":\"$data\"");
    sb.write('}');
    return sb.toString();
  }
}
